﻿@{
    ViewBag.Title = "所有流程";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@section HeadIncluder 
{
    <link href='@Url.Content("~/Content/public.css")'  type="text/css" rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")'  type="text/css" rel="stylesheet" />
    <script type="text/javascript" src=@Url.Content("~/Scripts/lhgdialog.min.js")> </script>

}
<div class="content" onkeydown="EnterClick(event.keyCode)">
    <div class="ss_box list_tble" style="margin-top: 20px;">
        <div class="s_box1">
            <table class="s_tble ">
                <tr>
                    <td class="aR">流程标题/序号:</td>
                    <td class="aL" colspan="2">
                        <input id="txtAppName" type="text" name="AppName" /></td>
                    <td class="aR">单据类型:</td>
                    <td class="aL" colspan="2">
                        <select id="dpProcessList" name="ProcessList">
                            <option value="" selected="selected">全部</option>
                            @{
                                IList<FCDB.Entity.WfProcess> list = ViewBag.ProcessList as IList<FCDB.Entity.WfProcess>;
                                foreach (var item in list)
                                {
                                <option value="@item.ProcessGUID"   >@item.ProcessName</option>
                                }
                            }
                        </select>
                    </td>
                    <td class="aR">发送时间:</td>
                    <td class="aL">
                        <input id="txtStartDate" type="text" />到<input id="txtEndDate" type="text" />
                    </td>
                </tr>
                <tr>
                    <td class="aR">创建人:</td>
                    <td class="aL">
                        <input id="txtUsersName" type="text" name="UsersName" disabled="disabled" style="width: 120px;" />
                        <input type="hidden" id="txtUsersID" name="txtUsersID" />
                    </td>
                    <td class="aL"><span class="btn_s btn_c1" style="margin-left: 4px;">
                        <a href="javascript:void(0)" onclick="addUsers()">添加</a></span> </td>
                    <td class="aR">创建部门:</td>
                    <td class="aL">
                        <input id="txtUsersDepartment" type="text" name="UsersDepartment" disabled="disabled" style="width: 120px;" />
                        <input type="hidden" id="txUsersDepartmentID" name="txtUsersDepartmentID" />
                    </td>
                    <td class="aL">
                        <span class="btn_s btn_c1">
                            <a href="javascript:void(0)" onclick="SelectDeparment(txUsersDepartmentID,txtUsersDepartment)">选择部门</a>
                        </span>
                    </td>
                    <td class="aR">流程状态:</td>
                    <td class="aL"> 
                             <select class="form-select" name="ProcessStatus">
                                <option value="0" >全部</option>
                                <option value="1" >流转中</option>
                                <option value="2" >已结束</option>
                            </select>
                         
                    </td>
                    <td class="aL"><span class="btn_s btn_c1" style="margin-left: 4px;"><a href="javascript:void(0)" onclick="onRefresh()">查找</a></span></td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div id="container" style="margin-right: 10px;">
    <div id="divGrid" style="width: 100%; height: 100%;">
        <table id="grid">
            <tr>
                <th>序号</th>
                <th>流程实例名称</th>
                <th>流程名称</th>
                <th>流程状态</th>
                <th>当前步骤</th>
                <th>处理人</th>
                <th>发送人</th>
                <th>创建时间</th>
                <th>处理时间</th>
            </tr>
        </table>
        <a></a>
    </div>
</div>
<script id="rowTemplate" type="text/x-kendo-tmpl">
    <tr>
        <td><a href="javascript:void(0)" onclick="onProcessClick('#: AppInstanceID #','#: AppName #','#: ProcessGUID #')">#: AppInstanceID # <i style="color:red">#: isRed # </i></a></td>
        <td><a href="javascript:void(0)" onclick="onProcessClick('#: AppInstanceID #','#: AppName #','#: ProcessGUID #')">#: AppName #</a></td>
        <td>#: ProcessName #</td>
        <td>#: ProcessState #</td>
        <td>#: ActivityName #</td>
        <td>#: ReceiveUserName #</td>
        <td>#: SendUserName #</td>
        <td>#: CreatedDateTime#</td>
        <td>#: LastUpdatedDateTime#</td>
    </tr>
</script>
<script type="text/javascript">
    function onProcessClick(AppInstanceID, AppName, ProcessGUID) {
        var url = '@Url.Action("ViewProccessInstance")' + "?AppInstanceID=" + AppInstanceID + "&&AppName=" + AppName + "&&ProcessGUID=" + ProcessGUID;
        var width = screen.availWidth * 0.8;
        var top = screen.availWidth * 0.05;
        var left = screen.availWidth * 0.1;
        var height = screen.availHeight * 0.8;
        var m = window.open(url, "", "width=" + width + "px, height=" + height + "px, top=" + top + "px, left=" + left + "px");
        if (m == 1) {
            onRefresh();
        }
    }
    function onClear() {
        $("#frm").reset();
    }
    function RefreshValue(selectPostList) {
        if (selectPostList != null || selectPostList != undefined) {
            var strNames = "";
            var strUserIDs = "";
            $.each(selectPostList, function (i, val) {
                strNames = val.Name;
                strUserIDs = val.UserID;
                $("#txtUsersName").val(strNames);
                $("#txtUsersID").val(strUserIDs);
            });
        }
    }
    function addUsers() {
        var url = '@Url.Action("EmployeeSelect", "Employee")'; 
        OpenSelectUserPop(url,RefreshValue);
        onRefresh();
    }
    function SelectDeparment(valtag, textTag) {
        var url = '@Url.Action("UCDepartmentSelect", "Form")';
         window.top.winObj = window;
         window.top.refresh = function (vals, txts) {
             $(valtag).val(vals);
             $(textTag).val(txts);
         };
         window.top.oDG = $.dialog({
             lock: true,
             background: '#FFF',
             opacity: 0.5,
             id: 'esDialog',
             title: '部门选择',
             titleAlign: 'left',
             content: "url:" + url,
             width: 570,
             height: 300,
             btnBar: false,
             lockScroll: true
         });
     }
     function EnterClick(va)
     {
         if(va==13)
         {
             onRefresh()
         }
     }
     function onRefresh() {
         var grid = $("#grid").data("kendoGrid");
         grid.dataSource.read();
     }
     function loadData() {
         $("#grid").kendoGrid({
             selectable: "multiple,row",
             dataSource: {
                 serverPaging: true,
                 pageSize: @FCDB.Web.Helpers.AppSettings.DefaultPageSize ,
                transport: {
                    read: {
                        url: '@Url.Action("Index")',
                         type: "POST",
                         dataType: "json",
                         data: {
                             dtStart: function () {
                                 return $("#txtStartDate").val();
                             },
                             dtEnd: function () {
                                 return $("#txtEndDate").val();
                             },
                             keyword: function () {
                                 return $("#txtAppName").val();
                             },
                             UserIDs: function () {
                                 return $("#txtUsersID").val();
                             },
                             DeparmentID: function () {
                                 return $("#txUsersDepartmentID").val();
                             },
                             ProcessGUID:function()
                             {
                                 return $("#dpProcessList").val();
                             }
                         }
                     }
                 },
               
                schema: {
                    model: {
                        fields: {
                            CreatedDateTime: { type: "date" },
                            LastUpdatedDateTime: { type: "date" }
                        }
                    },
                    //取出資料陣列
                    data: function (d) { return d.Data; },
                    //取出資料總筆數(計算頁數用)
                    total: function (d) { return d.TotalCount; }
                }
            },
            height: 600,
           
            pageable: {
                refresh: true,
                pageSizes: true
            },
            dataBinding: function (e) {
                for (var i = 0; i < e.items.length; i++) {
                    switch (e.items[i].ProcessState) {
                        case 0:
                            e.items[i].ProcessState = "未启动";
                            break;
                        case 1:
                            e.items[i].ProcessState = "准备";
                            break;
                        case 2:
                            e.items[i].ProcessState = "流转中";
                            break;
                        case 4:
                            e.items[i].ProcessState = "结束";
                            break;
                        case 8:
                            e.items[i].ProcessState = "挂起";
                            break;
                        case 16:
                            e.items[i].ProcessState = "取消";
                            break;
                        case 32:
                            e.items[i].ProcessState = "终止";
                            break;

                    }
                    e.items[i].CreatedDateTime = company(e.items[i].CreatedDateTime);
                    e.items[i].LastUpdatedDateTime = company(e.items[i].LastUpdatedDateTime);
                }
            },
            rowTemplate: kendo.template($("#rowTemplate").html())
        });
     }
      
     $(function () {
         loadData();
         $("#txtStartDate").kendoDatePicker({ format: "yyyy-MM-dd" });
         $("#txtEndDate").kendoDatePicker({ format: "yyyy-MM-dd" });
     });
     function company(CreatedDateTime) {
         var now = new Date(CreatedDateTime);

         var year = now.getFullYear();       //年
         var month = now.getMonth() + 1;     //月
         var day = now.getDate();            //日

         var hh = now.getHours();            //时
         var mm = now.getMinutes();          //分

         var clock = year + "-";

         if (month < 10)
             clock += "0";
         clock += month + "-";

         if (day < 10)
             clock += "0";

         clock += day + " ";

         if (hh < 10)
             clock += "0";

         clock += hh + ":";
         if (mm < 10) clock += '0';
         clock += mm;
         return clock;
     }
</script>
